﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:models="clr-namespace:Commanding.Modules.Order.PresentationModels"
    xmlns:converter="clr-namespace:Commanding.Modules.Order.Converter">
    
    <!-- Templates for showing validation errors (these could be declared in the application's styles to be used by several modules) -->
    <ControlTemplate x:Key="ErrorTemplate">
        <Border BorderBrush="Red" BorderThickness="1" Padding="2" CornerRadius="2">
            <AdornedElementPlaceholder />
        </Border>
    </ControlTemplate>
    <converter:ErrorConverter x:Key="errorConverter"/>
    <converter:DateConverter x:Key="dateConverter"/>
    <Style x:Key="TextBoxInError" TargetType="{x:Type TextBox}">
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Margin" Value="0,5,0,5"/>
        <Setter Property="AllowDrop" Value="true"/>
        <Setter Property="HorizontalContentAlignment" Value="left"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Grid>
                        <Border x:Name="Border" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1" Padding="2" CornerRadius="2">
                            <ScrollViewer Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleScrollViewer}" Background="{TemplateBinding Background}"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Validation.HasError" Value="true">
                            <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <!-- Presentation Model templates -->
    <DataTemplate DataType="{x:Type models:OrderPresentationModel}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="100"/>
                <ColumnDefinition  Width="*"/>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding OrderName}"  HorizontalContentAlignment="Left" FontWeight="Bold"/>
            <Label Grid.Row="1" Grid.Column="0">Delivery Date</Label>
            <Label Grid.Row="2" Grid.Column="0">Quantity</Label>
            <Label Grid.Row="3" Grid.Column="0">Price</Label>
            <Label Grid.Row="4" Grid.Column="0">Shipping</Label>
            <Label Grid.Row="5" Grid.Column="0">Total</Label>
            <TextBox Grid.Row="1" Grid.Column="1" Text="{Binding DeliveryDate, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True, Converter={StaticResource dateConverter}}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Style="{StaticResource TextBoxInError}" />
            <TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Quantity, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Style="{StaticResource TextBoxInError}" />
            <TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Price, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Style="{StaticResource TextBoxInError}" />
            <TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Shipping}" />
            <TextBox Grid.Row="5" Grid.Column="1" IsReadOnly="True"  Text="{Binding Total, Mode=OneWay}" />
            <Button Grid.Row="6" Grid.Column="1" Content="Save" Command="{Binding SaveOrderCommand}"></Button>
        </Grid>
    </DataTemplate>
    <DataTemplate DataType="{x:Type models:OrdersEditorPresentationModel}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="4*"/>
                <ColumnDefinition Width="6*"/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="0" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FCFFF5" BorderThickness="2,2,2,2" Margin="5" Padding="5">
                <ListView ItemsSource="{Binding Orders}" DisplayMemberPath="OrderName" IsSynchronizedWithCurrentItem="True" Width="Auto" Height="Auto" />
            </Border>
            <Border Grid.Column="1" CornerRadius="4,4,4,4" BorderBrush="#193441" Background="#FCFFF5" BorderThickness="2,2,2,2" Margin="5" Padding="5">
                <ContentControl Content="{Binding Orders/}" Width="Auto" Height="Auto"/>
            </Border>
        </Grid>
    </DataTemplate>
    <DataTemplate DataType="{x:Type models:OrdersToolbarPresentationModel}">
        <ToolBar>
            <Button Command="{Binding SaveAllOrdersCommand}">Save All Orders</Button>
            <Separator />
        </ToolBar>
    </DataTemplate>
</ResourceDictionary>
